home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / BorderedPanePanel.java < prev    next >
Text File  |  1998-06-30  |  5KB  |  150 lines

  1. /*
  2.  * @(#)BorderedPanePanel.java    1.3 98/01/31
  3.  *
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  *
  19.  */
  20.  
  21. import com.sun.java.swing.*;
  22. import com.sun.java.swing.event.*;
  23. import com.sun.java.swing.border.*;
  24.  
  25. import java.awt.*;
  26. import java.awt.event.*;
  27. import java.util.*;
  28. import java.io.*;
  29.  
  30. /**
  31.  * Borders, borders, everywhere....
  32.  *
  33.  * @version 1.3 01/31/98
  34.  * @author Jeff Dinkins
  35.  */
  36. public class BorderedPanePanel extends JPanel
  37. {
  38.     SwingSet swing;
  39.  
  40.     JPanel borderedPane;
  41.  
  42.     public BorderedPanePanel(SwingSet swing) {
  43.     this.swing = swing;
  44.  
  45.     // setBorderStyle(LOWERED);
  46.     setBorder(swing.emptyBorder10);
  47.     setLayout(new BorderLayout());
  48.  
  49.     borderedPane = new JPanel();
  50.     borderedPane.setLayout(new BorderLayout());
  51.     borderedPane.setBorder(BorderFactory.createTitledBorder("Bordered Pane"));
  52.  
  53.  
  54.     // Create title position controls
  55.     JPanel controls = new JPanel();
  56.     controls.setBorder(swing.emptyBorder20);
  57.     controls.setLayout(new BoxLayout(controls, BoxLayout.Y_AXIS));
  58.  
  59.     controls.add(Box.createRigidArea(swing.vpad10));
  60.  
  61.     JRadioButton b;
  62.     ButtonGroup group = new ButtonGroup();
  63.     JLabel label = new JLabel("Title Position:");
  64.     label.setFont(swing.boldFont);
  65.     controls.add(label);
  66.  
  67.     b = (JRadioButton) controls.add(new JRadioButton("Above Top"));
  68.     b.addActionListener(borderedPaneListener);
  69.     group.add(b);
  70.  
  71.     b = (JRadioButton) controls.add(new JRadioButton("Top"));
  72.     b.setSelected(true);
  73.     b.addActionListener(borderedPaneListener);
  74.     group.add(b);
  75.  
  76.     b = (JRadioButton) controls.add(new JRadioButton("Below Top"));
  77.     b.addActionListener(borderedPaneListener);
  78.     group.add(b);
  79.  
  80.     b = (JRadioButton) controls.add(new JRadioButton("Above Bottom"));
  81.     b.addActionListener(borderedPaneListener);
  82.     group.add(b);
  83.  
  84.     b = (JRadioButton) controls.add(new JRadioButton("Bottom"));
  85.     b.addActionListener(borderedPaneListener);
  86.     group.add(b);
  87.  
  88.      b = (JRadioButton) controls.add(new JRadioButton("Below Bottom"));
  89.     b.addActionListener(borderedPaneListener);
  90.     group.add(b);
  91.  
  92.     controls.add(Box.createRigidArea(swing.vpad10));
  93.     label = new JLabel("Title Justification:");
  94.     label.setFont(swing.boldFont);
  95.     controls.add(label);
  96.  
  97.     group = new ButtonGroup();
  98.      b = (JRadioButton) controls.add(new JRadioButton("Left"));
  99.     b.addActionListener(borderedPaneListener);
  100.     b.setSelected(true);
  101.     group.add(b);
  102.  
  103.      b = (JRadioButton) controls.add(new JRadioButton("Center"));
  104.     b.addActionListener(borderedPaneListener);
  105.     group.add(b);
  106.  
  107.      b = (JRadioButton) controls.add(new JRadioButton("Right"));
  108.     b.addActionListener(borderedPaneListener);
  109.     group.add(b);
  110.  
  111.     // Add panels 
  112.     add("Center", borderedPane);
  113.     borderedPane.add("Center", controls);
  114.     // add("East", controls);
  115.     }
  116.  
  117.     // Title Pane tile position
  118.     ActionListener borderedPaneListener = new ActionListener() {
  119.         public void actionPerformed(ActionEvent e) {
  120.             JRadioButton b = (JRadioButton) e.getSource();
  121.         TitledBorder border = (TitledBorder) borderedPane.getBorder();
  122.  
  123.             if(b.getText().equals("Above Top")) {
  124.         border.setTitlePosition(TitledBorder.ABOVE_TOP);
  125.         } else if(b.getText().equals("Top")) {
  126.         border.setTitlePosition(TitledBorder.TOP);
  127.         } else if(b.getText().equals("Below Top")) {
  128.         border.setTitlePosition(TitledBorder.BELOW_TOP);
  129.         } else if(b.getText().equals("Above Bottom")) {
  130.         border.setTitlePosition(TitledBorder.ABOVE_BOTTOM);
  131.         } else if(b.getText().equals("Bottom")) {
  132.         border.setTitlePosition(TitledBorder.BOTTOM);
  133.         } else if(b.getText().equals("Below Bottom")) {
  134.         border.setTitlePosition(TitledBorder.BELOW_BOTTOM);
  135.         } else if(b.getText().equals("Left")) {
  136.         border.setTitleJustification(TitledBorder.LEFT);
  137.         } else if(b.getText().equals("Center")) {
  138.         border.setTitleJustification(TitledBorder.CENTER);
  139.         } else if(b.getText().equals("Right")) {
  140.         border.setTitleJustification(TitledBorder.RIGHT);
  141.         }
  142.         
  143.             borderedPane.invalidate();
  144.             borderedPane.validate();
  145.             borderedPane.repaint();
  146.         }
  147.     };
  148.  
  149. }
  150.